<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.5,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no, email=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <!-- 删除苹果默认的工具栏和菜单栏 -->
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <!-- 设置苹果工具栏颜色 -->
    <meta name="format-detection" content="telphone=no, email=no" />
    <!-- 忽略页面中的数字识别为电话，忽略email识别 -->
    <!-- 启用360浏览器的极速模式(webkit) -->
    <meta name="renderer" content="webkit">
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
    <meta name="HandheldFriendly" content="true">
    <!-- 微软的老式浏览器 -->
    <meta name="MobileOptimized" content="320">
    <!-- uc强制竖屏 -->
    <meta name="screen-orientation" content="portrait">
    <!-- QQ强制竖屏 -->
    <meta name="x5-orientation" content="portrait">
    <!-- UC强制全屏 -->
    <meta name="full-screen" content="yes">
    <!-- QQ强制全屏 -->
    <meta name="x5-fullscreen" content="true">
    <!-- UC应用模式 -->
    <meta name="browsermode" content="application">
    <!-- QQ应用模式 -->
    <meta name="x5-page-mode" content="app">
    <!-- windows phone 点击无高光 -->
    <meta name="msapplication-tap-highlight" content="no">
    <title>虾客云-客户管理</title>
    <link rel="stylesheet" href="{{asset('css/reset.css')}}">
    <link rel="stylesheet" href="{{asset('css/main.css')}}">
    <link rel="stylesheet" href="{{asset('css/index.css')}}">
    <link rel="stylesheet" href="{{asset('css/yd_rl.css')}}" />
    <link rel="stylesheet" href="{{asset('css/LCalendar.css')}}" />
</head>
<body>
    <!-- 公共头部 -->
    <div class="g2_head-bg">
        <!-- 返回上一层 -->
        <p class="g2_head_goback-bg fl">
            <a href="javascript:history.back(-1)">
                <img src="{{asset('images/xky_icon0-1.png')}}" class="g2_head_goback_icon fl" alt="">
                <span class="g2_head_goback_del fl">返回</span>
            </a>
        </p>
        <p class="ym-tit fl">游客列表</p>
        <span class="g2_head_goback_del fr khtj_sx yklb_sx" style="display:block;">筛选</span>
        <div class="cl"></div>
    </div>
    <div class="g2_head-bg2"></div>
    <!-- 客户管理  游客列表 -->
    <div class="cjd_skjl-bg" id="khlb1">
        <div id="kaikuo">
        @foreach($tourist as $vo)
        <div class="cjd_khgllb-bg youkelist" myAttr="true">
            <input type="hidden" name="listid" value="{{$vo->id}}">
            <p class="cjd_khgllb_khname fl">{{$vo->tourist_name}}</p>
            <p class="cjd_khgllb_iphone fl">{{$vo->tourist_phone}}</p>
            <span class="cjd_khgllb_srtx fr">生日提醒</span>
            <p class="cjd_ykxq_sfzh fl">{{$vo->tourist_typename}}</p>
            <span class="cjd_ykxq_sp fr">{{$vo->tixing}}</span>
            <div class="cl"></div>
        </div>
        @endforeach
        </div>
        <!-- 加载更多按钮 -->
        <div class="jzmore-bg" style="margin-bottom:22vw;" id="jiazai">
            <img src="{{asset('images/jiazai.png')}}" alt="">
            <span>加载更多</span>
        </div>
        <input type="hidden" id="customer_ids" name="customer_id" value="">
        <form action="" id="customer_form">
            <input type="hidden" id="ids" name="ids" value="">
            <input type="hidden" id="moban" name="moban" value="">
        </form>
        <div class="khgl_khlbbtn-bg">
            <input type="button" class="khgl_yklbbtn yklbfsdx_btn fl" id="" value="发送短信" readonly>
        </div>
    </div>

    <!-- 客户列表 短信列表 -->
    <div class="khlb_dxlb-bg" id="khlb2">
        <ul class="khlb_dxlb-bg2">
            @foreach($duanxin as $vo)
            <li class="khlb_dxlb duanxinlist">
                <input type="hidden" name="duanxinid" value="{{$vo->id}}">
                <p class="khlb_dxlb-tit">{{$vo->title}}</p>
                <span class="khlb_dxlb_del">
                    {{$vo->content}}
                </span>
            </li>
            @endforeach
            <input type="button" id="fasong" class="khlb_dxlb_fsbtn" style="width:100%;" value="发送短信" readonly>
        </ul>
    </div>
    <!-- 客户列表 筛选条件 -->
    <div class="khlb_sx-bg" id="khlb3">
        <form action="" id="youkesousuo">
            <input type="hidden" id="shuliang" name="shuliang" value="{{$shuliang}}">
            <ul class="khs2">
                <li class="khs2_list">
                    <p class="khs2_tit fl">游客类别</p>
                    <span class="sewv fl" style="width:48%;">
                        <span class="sewvtop">
                            <input type="text" name="tourist_type" class="khs2_del fl" placeholder="请选择游客类别" value="">
                            <em>
                                <img src="{{asset('images/xky_icon9.png')}}">
                            </em>
                        </span>
                        <ul class="sewvbm">
                            <li>单位</li>
                            <li>个人</li>
                        </ul>
                    </span>
                    <div class="cl"></div>
                </li>
                <li class="khs2_list">
                    <p class="khs2_tit fl">单位名称</p>
                    <input type="text" name="tourist_typename" class="khs2_del fl" placeholder="请填写单位名称" value="">
                    <div class="cl"></div>
                </li>
                <li class="khs2_list">
                    <p class="khs2_tit fl">游客姓名</p>
                    <input type="text" name="tourist_name" class="khs2_del fl" placeholder="请填写游客姓名" value="">
                    <div class="cl"></div>
                </li>
                <li class="khs2_list">
                    <p class="khs2_tit fl">游客电话</p>
                    <input type="text" name="tourist_phone" class="khs2_del fl" placeholder="请填写游客电话" value="">
                    <div class="cl"></div>
                </li>
                <input type="sibmit" id="sousuo" class="gdsx_search-btn" value="搜索">
            </ul>
        </form>
    </div>
    <!-- 遮罩 -->
    <!-- loading 小圆圈 -->
    <div class="z2_loading-bg" style="width:100%;height:100%;background:rgba(255,255,255,0.6);position:fixed;;left:0;top:0;">
        <img src="{{asset('images/loading1.gif')}}" style="width:10%;position:fixed;left:0;right:0;top:0;bottom:0;margin:auto;" alt="">
    </div>
    <!-- loadning对号 -->
    <div class="duihao" style="width:100%;height:100%;position:fixed;;left:0;top:0;display:none;">
        <img src="{{asset('images/duihao.png')}}" style="width:10%;position:fixed;left:0;right:0;top:0;bottom:0;margin:auto;" alt="">
    </div>
     <!-- 提示信息 --> 
    <p id="tishi" style="display:none;position:fixed;left:0;right:0;top:0;bottom:0;margin:auto;width:94%;height:8vw;line-height:8vw;color:#fff;font-size:1.6rem;text-align:center;background:rgba(0,0,0,0.5);border-radius:4px;"></p>
    <script src="{{asset('js/jquery.min.js')}}"></script>
    <script src="{{asset('js/fastclick.min.js')}}"></script>
</body>
    <script src="{{asset('js/LCalendar.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/index.js')}}" type="text/javascript" charset="utf-8"></script>
    <script>
    $(function () {
        FastClick.attach(document.body);
    });
    // 执行游客筛选查询
    $(function () {
        $("#sousuo").click(function(){
            var d = {};
            var t = $('#youkesousuo').serializeArray();
            $.each(t, function() {
              d[this.name] = this.value;
            });
            var data=JSON.stringify(d);
            // alert(data);
            $.ajax({
                url:"{{url('youkesousuo')}}",
                type:'post', //GET
                async:false,    //或false,是否异步
                data:{'_token':'{{csrf_token()}}','data':data},
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(){
                    console.log('发送前');
                    $('.z2_loading-bg').show();
                },
                success:function(data){
                    if(data=="false"){
                        $('.z2_loading-bg').hide();
                        $("#tishi").html('搜索失败');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(1500);
                        window.location.href = "{{url('/')}}";
                    }else{
                        var html="";
                        $.each(data.tourist,function(i,item){
                            html+="<div class=\"cjd_khgllb-bg kehulist\"  myAttr=\"true\"><input type=\"hidden\" name=\"listid\" value=\""+item.id+"\"><p class=\"cjd_khgllb_khname fl\">"+item.tourist_name+"<\/p><p class=\"cjd_khgllb_iphone fl\">"+item.tourist_phone+"<\/p><span class=\"cjd_khgllb_srtx fr\">生日提醒<\/span><p class=\"cjd_ykxq_sfzh fl\">"+item.tourist_typename+"<\/p><span class=\"cjd_ykxq_sp fr\">"+item.tixing+"<\/span><div class=\"cl\"><\/div><\/div>";
                    　　});
                        $("#kaikuo").html(html);
                        $("#shuliang").val(data.shuliang);
                        $('.cjd_khgllb-bg').click(function(){
                            if($(this).attr("myAttr")=="true"){
                                $("#customer_ids").val($("#customer_ids").val()+$(this).children().eq(0).val()+',');
                                $(this).attr("myAttr","false");
                                $(this).css('background', '#eaeaea');
                            }else{
                                $("#customer_ids").val($("#customer_ids").val().replace($(this).children().eq(0).val()+',',""));
                                $(this).attr("myAttr","true");
                                $(this).css('background', '#fff');
                            }
                        })
                    }
                }, 
                complete:function(){
                    location.hash = 'khlb1';
                    $("#khlb1").show();
                    $("#khlb2").hide();
                    $("#khlb3").hide();
                    $("#khlb4").hide();
                    $("#khlb5").hide();
                    $('.z2_loading-bg').hide();
                    $('.duihao').show();
                    $('.duihao').hide(1000);
                }
            })
        });  
    });
    // 点击加载按钮
    $("#jiazai").click(function(){
        var shu=$("#shuliang").val();
        $("#shuliang").val(shu*1+10);
        var d = {};
        var t = $('#youkesousuo').serializeArray();
        $.each(t, function() {
          d[this.name] = this.value;
        });
        var data=JSON.stringify(d);
         $.ajax({
                url:"{{url('youkesousuo')}}",
                type:'post', //GET
                async:false,    //或false,是否异步
                data:{'_token':'{{csrf_token()}}','data':data},
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(){
                    console.log('发送前');
                    $('.z2_loading-bg').show();
                },
                success:function(data){
                    if(data=="false"){
                        $('.z2_loading-bg').hide();
                        $("#tishi").html('搜索失败');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(1500);
                        window.location.href = "{{url('/')}}";
                    }else{
                        var html="";
                        $.each(data.tourist,function(i,item){
                            html+="<div class=\"cjd_khgllb-bg kehulist\"  myAttr=\"true\"><input type=\"hidden\" name=\"listid\" value=\""+item.id+"\"><p class=\"cjd_khgllb_khname fl\">"+item.tourist_name+"<\/p><p class=\"cjd_khgllb_iphone fl\">"+item.tourist_phone+"<\/p><span class=\"cjd_khgllb_srtx fr\">生日提醒<\/span><p class=\"cjd_ykxq_sfzh fl\">"+item.tourist_typename+"<\/p><span class=\"cjd_ykxq_sp fr\">"+item.tixing+"<\/span><div class=\"cl\"><\/div><\/div>";
                    　　});
                        $("#kaikuo").html(html);
                        $("#shuliang").val(data.shuliang);
                        $('.cjd_khgllb-bg').click(function(){
                            if($(this).attr("myAttr")=="true"){
                                $("#customer_ids").val($("#customer_ids").val()+$(this).children().eq(0).val()+',');
                                $(this).attr("myAttr","false");
                                $(this).css('background', '#eaeaea');
                            }else{
                                $("#customer_ids").val($("#customer_ids").val().replace($(this).children().eq(0).val()+',',""));
                                $(this).attr("myAttr","true");
                                $(this).css('background', '#fff');
                            }
                        })
                    }
                }, 
                complete:function(){
                    location.hash = 'khlb1';
                    $("#khlb1").show();
                    $("#khlb2").hide();
                    $("#khlb3").hide();
                    $("#khlb4").hide();
                    $("#khlb5").hide();
                    $('.z2_loading-bg').hide();
                    $('.duihao').show();
                    $('.duihao').hide(1000);
                }
            })
    })
    window.onload = function (event) {
        location.hash = 'khlb1';
        $("#khlb1").show();
        $("#khlb2").hide();
        $("#khlb3").hide();
        $(".z2_loading-bg").hide();
    }
    $(window).on('hashchange', function (e) {
        var id = location.hash.substr(1);
        $("#" + id).show()

        if (id == "khlb1") {
            $("#khlb1").show();
            $("#khlb2").hide();
            $("#khlb3").hide();
            $('.yklb_sx').show();
            $('.ym-tit').html('游客列表');
        } else if (id == "khlb2") {
            $("#khlb1").hide();
            $("#khlb2").show();
            $("#khlb3").hide();
            $('.yklb_sx').hide();
            $('.ym-tit').html('发送短信');
        } else if (id == "khlb3") {
            $("#khlb1").hide();
            $("#khlb2").hide();
            $("#khlb3").show();
            $('.yklb_sx').show();
            $('.ym-tit').html('游客列表筛选');
        }
    })
    // 客户列表点击出现筛选
    $('.khtj_sx').click(function () {
        location.hash = 'khlb3';
        $("#khlb1").hide();
        $("#khlb2").hide();
        $("#khlb3").show();
        $('.yklb_sx').show();
        $('.ym-tit').html('游客列表筛选');
    })

    // 游客列表选项点击
    $('.cjd_khgllb-bg').click(function(){
        if($(this).attr("myAttr")=="true"){
            $("#customer_ids").val($("#customer_ids").val()+$(this).children().eq(0).val()+',');
            $(this).attr("myAttr","false");
            $(this).css('background', '#eaeaea');
        }else{
            $("#customer_ids").val($("#customer_ids").val().replace($(this).children().eq(0).val()+',',""));
            $(this).attr("myAttr","true");
            $(this).css('background', '#fff');
        }
    })
    $('.yklbfsdx_btn').click(function () {
        if($("#customer_ids").val()==""){
            $("#tishi").html('没有选择客户');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(2000);
        }else{
            // $(".kehulist").attr("myAttr","true");
            $("#listid").val($("#customer_ids").val());
            // $("#customer_ids").val("");
            location.hash = 'khlb2';
            $("#khlb1").hide();
            $("#khlb2").show();
            $("#khlb3").hide();
            $("#khlb4").hide();
            $('.khlb_sx').hide();
            $('.ym-tit').html('发送短信');
        }
    })
    // 点击短信列表选项
    $('.khlb_dxlb').click(function () {
        $(".duanxinlist").css('background', '#fff');
        $("#moban").val($(this).children().eq(0).val());
        $(this).css('background', '#eaeaea');
    });
    // 执行短信发送
    $("#fasong").click(function(){
        if($("input[name='listid']").val()==''){
            $("#tishi").html('客户必须选择');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else if($("input[name='moban']").val()==''){
            $("#tishi").html('短信模板必须选择');
            $("#tishi").stop(true, true).fadeIn('fast');
            $("#tishi").fadeOut(1500);
        }else{
            var d = {};
            var t = $('#customer_form').serializeArray();
            $.each(t, function() {
              d[this.name] = this.value;
            });
            var data=JSON.stringify(d);
            $.ajax({
                url:"{{url('youkeduanxin')}}",
                type:'post', 
                async:false,    //或false,是否异步
                data:{'_token':'{{csrf_token()}}','data':data},
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(){
                    console.log('发送前');
                    $('.z2_loading-bg').show();
                },
                success:function(data){
                    if(data=="yuebuzu"){
                        $("#tishi").html('余额不足！');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(2000);
                    }else{
                        $(".kehulist").attr("myAttr","true");
                        $("#customer_ids").val("");
                        $(".z2_loading-bg").hide();
                        $("#tishi").html('成功'+data.chenggong+'条，失败'+data.shibai+'条。');
                        $("#tishi").stop(true, true).fadeIn('fast');
                        $("#tishi").fadeOut(2000);
                        window.location.reload();
                    }
                }, 
            })
        }
    });
    </script>
</html>